/*
* Copyright (C) 2004-2006  Autodesk, Inc.
* 
* This library is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser
* General Public License as published by the Free Software Foundation.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*
*/

#include "stdafx.h"
#include "FdoWcsContents.h"
#include "FdoWcsXmlGlobals.h"
#include "FdoWcsCoverageSummary.h"
#include "FdoWcsCoverageSummaryCollection.h"
#include "FdoCommonOSUtil.h"

FdoWcsContents::FdoWcsContents(void)
{
    mCoverageSummaryCollection = FdoWcsCoverageSummaryCollection::Create();
}

FdoWcsContents::~FdoWcsContents(void)
{
}

FdoWcsContents* FdoWcsContents::Create()
{
    return new FdoWcsContents();
}

void FdoWcsContents::Dispose()
{
    delete this;
}

FdoWcsCoverageSummaryCollection* FdoWcsContents::GetCoverageSummaryCollection() const
{
    return FDO_SAFE_ADDREF(mCoverageSummaryCollection.p);
}

void FdoWcsContents::InitFromXml(FdoXmlSaxContext* context, FdoXmlAttributeCollection* attrs)
{
    try
    {
        VALIDATE_ARGUMENT(context);
        VALIDATE_ARGUMENT(attrs);
    }
    catch (FdoException* ex) 
    {
        context->AddError(ex);
        ex->Release();
    }
}

FdoXmlSaxHandler* FdoWcsContents::XmlStartElement( FdoXmlSaxContext* context, FdoString* uri, FdoString* name, FdoString* qname, FdoXmlAttributeCollection* atts )
{
    FdoXmlSaxHandler* pRet = NULL;

    try
    {
        VALIDATE_ARGUMENT(context);
        VALIDATE_ARGUMENT(name);

        pRet = BaseType::XmlStartElement(context, uri, name, qname, atts);
        if (pRet == NULL)
        {
            if (FdoCommonOSUtil::wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageSummary) == 0)
            {
                FdoWcsCoverageSummaryP pCoverageSummary = FdoWcsCoverageSummary::Create();

                FdoWcsCoverageSummaryCollectionP pCoverageSummaries = GetCoverageSummaryCollection();
                pCoverageSummaries->Add(pCoverageSummary);

                pRet = pCoverageSummary;
            }
        }
    }
    catch (FdoException* e)
    {
        context->AddError(e);
        e->Release();
    }
    
    return pRet;
}

FdoBoolean FdoWcsContents::XmlEndElement(FdoXmlSaxContext* context, FdoString* uri, FdoString* name, FdoString* qname)
{
    //try
    //{
    //    VALIDATE_ARGUMENT(context);
    //    VALIDATE_ARGUMENT(name);

    //    if (FdoCommonOSUtil.wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageSummary))
    //    {
    //        FdoWcsCoverageSummaryCollectionP pCoverageSummaries = GetCoverageSummaryCollection();

    //    }
    //}
    //catch (FdoException* ex) 
    //{
    //    context->AddError(ex);
    //    ex->Release();
    //}

    return BaseType::XmlEndElement(context, uri, name, qname);
}
